﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication.Models;
using DAO;

namespace WebApplication.Controllers
{
    public class NotificationsController : CRUDController<Notification, NotificationModel>
    {
        DataManager dm;
        public NotificationsController()
        {
            dm = new DataManager();
        }

        public override ActionResult List(string search)
        {
            if(!string.IsNullOrEmpty(search))
                return View(dm.NotificationsManager.GetAll().Where(t => t.Name.Contains(search)));
            return View(dm.NotificationsManager.GetAll());
        }

        protected override DAO.Repositories.BaseRepository<Notification> Repository
        {
            get
            {
                return dm.NotificationsManager;
            }
        }

        protected override DataManager Dm
        {
            get
            {
                return dm;
            }
        }
        //public ActionResult Add()
        //{
        //    return View();
        //}

        //[HttpPost]
        //public ActionResult Add(NotificationModel notification)
        //{
        //    if (!ModelState.IsValid)
        //    {
        //        ViewData["errors"] = "Объект не валиден";
        //        return View(notification);
        //    }
        //    dm.NotificationsManager.Add(NotificationModel.ToEfEntity(notification));
        //    dm.SaveChanges();
        //    return RedirectToAction("List");
        //}

        //public ActionResult Edit(int id)
        //{
        //    return View(dm.NotificationsManager.GetById(id));
        //}

        //[HttpPost]
        //public ActionResult Edit(Notification notification)
        //{
        //    if (!ModelState.IsValid)
        //    {
        //        ViewData["errors"] = "Объект не валиден";
        //        return View(notification);
        //    }
        //    dm.NotificationsManager.Edit(notification);
        //    dm.SaveChanges();
        //    return RedirectToAction("List");
        //}

        //public ActionResult Delete(int id)
        //{
        //    dm.NotificationsManager.Delete(id);
        //    dm.SaveChanges();
        //    return RedirectToAction("List");
        //}

        public ActionResult GetNotificationsUsers()
        {
            return View(dm.NotificationsManager.GetAll());
        }

    }
}
